#ifndef VEC3D
#define VEC3D

#include <base\vec3f.h>

#include <cmath>

struct vec3d {

  double x;
  double y;
  double z;

  vec3d() : x(0.0), y(0.0), z(0.0) {
  }

  vec3d(vec3f p) : x(p.x), y(p.y), z(p.z) {
  }

  vec3d(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {
  }

  vec3d operator-(vec3d b) {
    return vec3d(x - b.x, y - b.y, z - b.z);
  }

  vec3d operator+(vec3d b) {
    return vec3d(x + b.x, y + b.y, z + b.z);
  }

  vec3d operator*(float value) const {
    return vec3d(x * value, y * value, z * value);
  }

  vec3d operator/(float value) const {
    return vec3d(x / value, y / value, z / value);
  }

  double &operator[](int index) {
    if (index == 0) return x;
    else if (index == 1) return y;
    else return z;
  }

  bool operator==(vec3d b) {
    return (x == b.x && y == b.y && z == b.z);
  }

  bool operator!=(vec3d b) {
    return !(x == b.x && y == b.y && z == b.z);
  }

  double dot(const vec3d & v) const { 
    return x * v.x + y * v.y + z * v.z; 
  }

  double length() {
    return((double)sqrt(x*x + y*y + z*z));
  }

  void normalize() {
    double len;
    len = length();
	  if (len) {
		  x /= len;
		  y /= len;
		  z /= len;
	  }
  }

  vec3f toFloat() {
    return vec3f((float) x, (float) y, (float) z);
  }
};

#endif